//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.周赛.周赛447;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;

public class Q1 {
    public Q1() {
    }

    public static void main(String[] args) {
        int[][] buildings = new int[][]{{1, 2}, {2, 1}, {3, 1}, {2, 3}, {3, 3}, {2, 2}, {3, 2}};
        System.out.println(countCoveredBuildings(3, buildings));
    }

    public static int countCoveredBuildings(int n, int[][] buildings) {
        HashMap<Integer, List<Integer>> mapX = new HashMap(n);
        HashMap<Integer, List<Integer>> mapY = new HashMap(n);

        for(int i = 1; i <= n; ++i) {
            mapX.put(i, new ArrayList());
            mapY.put(i, new ArrayList());
        }

        int buildN = buildings.length;

        for(int i = 0; i < buildN; ++i) {
            int x = buildings[i][0];
            int y = buildings[i][1];
            List<Integer> xlist = (List)mapX.get(x);
            xlist.add(y);
            mapX.put(x, xlist);
            List<Integer> ylist = (List)mapY.get(y);
            ylist.add(x);
            mapY.put(y, ylist);
        }

        for(int i = 1; i <= n; ++i) {
            List<Integer> xlist = (List)mapX.get(i);
            List<Integer> ylist = (List)mapY.get(i);
            xlist.sort((Comparator)null);
            ylist.sort((Comparator)null);
        }

        int count = 0;

        for(int i = 1; i <= n; ++i) {
            List<Integer> xlist = (List)mapX.get(i);
            if (xlist.size() >= 3) {
                for(int j = 1; j < xlist.size() - 1; ++j) {
                    List<Integer> ylist = (List)mapY.get(xlist.get(j));
                    if (ylist.size() >= 3 && i > (Integer)ylist.get(0) && i < (Integer)ylist.get(ylist.size() - 1)) {
                        ++count;
                    }
                }
            }
        }

        return count;
    }
}
